import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_high_input_page.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_picker_photo.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_picker_video.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_sure_sheet.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/widget_extension.dart';
import 'package:safetymonitor/generated/assets.dart';

import 'snap_shot_controller.dart';

/// 随手拍页面
class SnapShotPage extends StatelessWidget {
  SnapShotPage({super.key});

  final controller = Get.put(SnapShotController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            backgroundColor: const Color(0xFFF7FBFE),
            appBar: CustomAppBar(
              titleText: '随手拍',
              actions: [
                SvgPicture.asset(
                  Assets.svgIconHistory,
                  height: 18.w,
                  width: 18.w,
                ).marginOnly(right: 18.w).clickOnce(controller.goHistory),
              ],
            ),
            body: SingleChildScrollView(
              child: Column(
                children: [
                  AppGaps.vGap20,
                  _getBasisContentView(),
                  AppGaps.vGap20,
                  _getOtherContentView(),
                  AppGaps.vGap60,
                ],
              ),
            ),
            bottomSheet: CustomSureSheet(onTap: controller.confirm),
          );
        });
  }

  /// 选择框
  Widget _getChoiceView(String title, String value, {String? hint}) {
    return Column(
      children: [
        Row(
          children: [
            Text(
              title,
              style: TextStyle(fontSize: 14.sp, height: 1.2, color: const Color(0xFF262F38), fontWeight: FontWeight.w400),
            ),
            AppGaps.hGap50,
            Expanded(
              child: Container(
                alignment: Alignment.centerRight,
                child: Text(
                  value == '' ? '请选择${hint ?? title}' : value,
                  style: TextStyle(
                    fontSize: 14.sp, height: 1.2, color: value == '' ? const Color(0xFFA0A7B5) : const Color(0xFF666666), //const Color(0xFF262F38),
                  ),
                ),
              ),
            ),
            AppGaps.hGap6,
            Icon(Icons.arrow_forward_ios, size: 20.w, color: const Color(0xFF6C779C))
          ],
        )
      ],
    );
  }

  /// 填写输入内容
  Widget _getBasisContentView() {
    return Container(
      padding: EdgeInsets.all(20.w),
      margin: EdgeInsets.symmetric(horizontal: 20.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10.w),
      ),
      child: Column(
        children: [
          _getChoiceView('隐患确认人', controller.confirmBy.getShowName()).clickOnce(controller.selectReportingPersonnel),
          Divider(height: 0.5.w, color: const Color(0xffEAF2FA)).marginSymmetric(vertical: 20.w),
          _getChoiceView('风险点', controller.riskPoint.getShowName()).clickOnce(controller.selectRiskPoint),
          Divider(height: 0.5.w, color: const Color(0xffEAF2FA)).marginSymmetric(vertical: 20.w),
          _getChoiceView('作业活动/设备设施', controller.securityControl.getShowName(), hint: '').clickOnce(controller.selectWorkActivity),
          Divider(height: 0.5.w, color: const Color(0xffEAF2FA)).marginSymmetric(vertical: 20.w),
          CustomHighInputPage(
            title: '隐患描述：',
            topPadding: 0,
            isRequired: false,
            isShowDivider: false,
            text: controller.description,
            hintText: '请输入隐患描述',
            onCallBack: (value) {
              controller.description = value;
            },
          ),
        ],
      ),
    );
  }

  /// 获取其他信息
  Widget _getOtherContentView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 20.w),
      margin: EdgeInsets.symmetric(horizontal: 20.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10.w),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          CustomPickerPhoto(
            title: '拍照:',
            maxCount: 9,
            imagesList: controller.dangerImages,
          ),
          Divider(height: 0.5.w, color: const Color(0xffEAF2FA)),
          CustomPickerVideo(
            title: '拍摄:',
            maxCount: 1,
            videoList: controller.dangerVideo,
          ),
        ],
      ),
    );
  }
}
